package com.quwan.manager.controller;

import com.quwan.common.BaseController;
import com.quwan.common.result.ApiResult;
import com.quwan.constans.CacheKey;
import com.quwan.entity.TScaleSetting;
import com.quwan.entity.TSystemPay;
import com.quwan.manager.service.SystemService;
import com.quwan.utils.redis.Redis;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author quan
 * @date 2021-10-25 15:24
 */

@Api(tags = "系统设置")
@RestController
@RequiredArgsConstructor
@RequestMapping("mgr/system")
public class SystemController extends BaseController {
    private final SystemService systemService;
    private  final Redis redis;


    @ApiOperation("支付开关列表")
    @GetMapping("/pay")
    public ApiResult<List<TSystemPay>> payMethodList() {
        return ApiResult.success(systemService.getPayPowerList());
    }

    @ApiOperation("开启/关闭 支付")
    @PostMapping("/pay/upd")
    public ApiResult changePayPowerStatus(@ApiParam("主键id") @RequestParam String id,
                                          @ApiParam("0关闭 1开启") @RequestParam String status) {
        systemService.changePayPowerStatus(id, status);
        return ApiResult.success();
    }

    @ApiOperation("关键词过滤数据")
    @PostMapping("/filter/kw")
    public ApiResult getKeyword() {
        return ApiResult.success(redis.get(CacheKey.DATA.filterKeyword));
    }

    @ApiOperation("关键词过滤修改")
    @PostMapping("/upd/kw")
    public ApiResult updateKeyword( @RequestParam String str) {
        redis.set(CacheKey.DATA.filterKeyword,str);
        return ApiResult.success();
    }


    @ApiOperation("支付控制修改")
    @PostMapping("/pay/edit")
    public ApiResult updPayPower(@RequestParam String id, @RequestParam String name) {
        if (systemService.updPayPower(id, name))
            return ApiResult.success();
        return ApiResult.failed();
    }

    @ApiOperation("支付控制修改")
    @PostMapping("/pay/add")
    public ApiResult addPayPower(TSystemPay systemPay) {
        if (systemService.addPayPower(systemPay))
            return ApiResult.success();
        return ApiResult.failed();
    }
    @ApiOperation("推广配置修改")
    @PostMapping("/spread/list")
    public ApiResult scaleList() {

        return ApiResult.success(systemService.getSpreadList());
    }

    @ApiOperation("推广配置修改")
    @PostMapping("/spread/update")
    public ApiResult scaleUpdate(String id , BigDecimal scale) {
         boolean success   =  systemService.updateScale(id,scale);
        return ApiResult.success();
    }



}
